package com.exartisan.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.exartisan.bean.Event;
import com.exartisan.util.FontUtil;
import com.exartisan.yn_event.R;
import com.loopj.android.image.SmartImageView;

public class HomeListAdapter extends BaseAdapter {
	private LayoutInflater inflater;
	private Context ctx;
	private ArrayList<Event> events;

	public HomeListAdapter(Context context, ArrayList<Event> events) {
		inflater = LayoutInflater.from(context);
		this.ctx = context;
		this.events = events;
	}

	@Override
	public int getCount() {
		return events.size();
	}

	@Override
	public Object getItem(int position) {
		return events.get(position);
	}

	@Override
	public long getItemId(int pos) {
		return events.get(pos).getEventID();
	}

	@Override
	public View getView(int pos, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null){
			holder = new ViewHolder();
		convertView = inflater.inflate(R.layout.new_event_row, null);
		holder.imgCover = (SmartImageView) convertView.findViewById(R.id.img_event);
		holder.tvEventName = (TextView) convertView.findViewById(R.id.tv_event_name);
		holder.tvEventDesc = (TextView) convertView.findViewById(R.id.tv_event_desc);
		holder.tvEventName.setTypeface(FontUtil.loadFontFromAssets(ctx, FontUtil.TAHOMABD));
		holder.tvEventDesc.setTypeface(FontUtil.loadFontFromAssets(ctx, FontUtil.ARIAL));
		convertView.setTag(holder);
		} else
			holder = (ViewHolder) convertView.getTag();
		holder.tvEventName.setText(events.get(pos).getEventName());
		holder.tvEventDesc.setText(events.get(pos).getDescription());
		holder.imgCover.setImageUrl(events.get(pos).getThumbUrl());
		return convertView;
	}
	
	class ViewHolder {
		SmartImageView imgCover;
		TextView tvEventName;
		TextView tvEventDesc;
	}

}
